/*
 * dwr_ipoque.h
 *
 *  Created on: 21/05/2013
 *      Author: jose
 */

#ifndef DWR_IPOQUE_H_
#define DWR_IPOQUE_H_

#define u8  unsigned char
#define u16 short unsigned
#define u32 unsigned
#define u64 unsigned long long

typedef struct ipoque_unique_flow_ipv4_address_struct {
	/**
	 * lower ip
	 */
	u32 lower_ip;
	/**
	 * upper ip
	 */
	u32 upper_ip;
	/* we need 3 dummies to fill up to ipv6 address size */
	/**
	 * this is only needed to become the same size like a unique ipv6 struct
	 */
	u64 dummy[3];
} ipoque_unique_flow_ipv4_address_struct_t;

/**
 * struct for a unique ipv6 flow address
 */
typedef struct ipoque_unique_flow_ipv6_address_struct {
	/**
	 * lower ip
	 */
	u64 lower_ip[2];
	/**
	 * upper ip
	 */
	u64 upper_ip[2];
} ipoque_unique_flow_ipv6_address_struct_t;


/**
 * struct for a unique ipv4 and ipv6 5-tuple (ip,ip,port,port,protocol)
 */
typedef struct ipoque_unique_flow_ipv4_and_6_struct {
	/* only ip addresses are different, to minimize compare operations for hash tables, store ipv4 or ipv6 always in the first bit */
	/**
	 * saves if it is a ipv6, if it false so it is a ipv4
	 */
	u16 is_ip_v6;
	/**
	 * the protocol, 16 bit wide for alignemt reasons
	 */
	u16 protocol; /* for alignment reason, protocol is 16 bit, not 8 bit */
	/**
	 * the port of the lower ip address
	 */
	u16 lower_port;
	/**
	 * the port of the upper ip address
	 */
	u16 upper_port;
	union {
		/**
		 * the ipv4 flow address struct. use the same memory area like ipv6 (union)
		 */
		struct ipoque_unique_flow_ipv4_address_struct ipv4;
		/**
		 * the ipv6 flow address struct. use the same memory area like ipv4 (union)
		 */
		struct ipoque_unique_flow_ipv6_address_struct ipv6;
	} ip;
} ipoque_unique_flow_ipv4_and_6_struct_t;


typedef struct ipoque_int_one_line_struct {
	const u8 *ptr;
	u16 len;
} ipoque_int_one_line_struct_t;

ipoque_unique_flow_ipv4_and_6_struct_t * dwr_ipoque_key_create(u32 source_ip, u32 dest_ip,
		u16 source_port, u16 dest_port);

void
dwr_key_print(ipoque_unique_flow_ipv4_and_6_struct_t * key);

#endif /* DWR_IPOQUE_H_ */
